﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using ESOL.Common.Entity;
using System.IO;

namespace ESOL.Services
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的接口名“IService1”。
    [ServiceContract]
    public interface ISysService
    {
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool TestConnect();

        // TODO: 在此添加您的服务操作
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DateTime GetSysCurTime();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        SysInfoEntity AddSysInfo(SysInfoEntity sysInfo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateSysInfo(SysInfoEntity sysInfo);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetSysInfoPages(int pageIndex, int pageCount);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetSysFcByCondition(string rowCount, string condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        SysFcEntity AddSysFc(SysFcEntity sysFc);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateSysFc(SysFcEntity sysFc);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetSysPeriodPageByFc(SysFcEntity sysFc, int pageIndex, int pageCount);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        SysPeriodEntity AddSysPeriod(SysPeriodEntity SysPeriod);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysPeriodEntity> AddSysPeriodsByMonth(SysFcEntity sysFc, int month, int periodType);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateSysPeriod(SysPeriodEntity sysPeriod);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        SysWorkingPeriodEntity AddSysWorkingPeriod(SysWorkingPeriodEntity sysWorkingPeriod);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool AddSysWorkingPeriodsForPeriod(SysPeriodEntity sysPeriod, List<SysWorkingPeriodEntity> lwfp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool AddSysWorkingPeriodsByFc(SysFcEntity sysFc, List<SysWorkingPeriodEntity> lwfp);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateSysWorkingPeriod(SysWorkingPeriodEntity sysWorkingPeriod);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWPeriod(SysPeriodEntity sysPeriod);

        ////查询SYS_TABLE
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //DataSet GetSysTabByCondition(TabQueryCondition condition);

        ////新增SYS_TABLE
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //bool AddSysTab(SysTableEntity sysTable);

        ////更新SYS_TABLE
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //bool UpdateSysTab(SysTableEntity sysTable);

        ////删除SYS_TABLE
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //bool DelSysTab(SysTableEntity sysTable);

        //查询菜单
        //[OperationContract]
        //[FaultContract(typeof(ProcessExecutionFault))]
        //DataSet GetAllSecMenu();

        //查询业务表单附件内容

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysAttachmentEntity> GetAllAttch(string formName, string rowId);

        //新增业务表单附件内容
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddAttch(SysAttachmentEntity attch);

        //更新业务表单附件内容
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateAttch(SysAttachmentEntity attch);

        //删除业务表单附件内容
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelAttch(SysAttachmentEntity attch);

        /// <summary>
        /// 上传附件
        /// </summary>
        /// <returns>返回保存文件全路径</returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        FileUploadReturnMessage UploadAttach(AttachUploadMessage request);

        /// <summary>
        /// 下载附件
        /// </summary>
        /// <param name="fileName">全路径文件名</param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        AttachDownloadReturnMessage DownloadAttach(FileDownloadMessage request);

        /// <summary>
        /// 文件管理上传文件
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        FileUploadReturnMessage UploadFile(FileUploadMessage request);

        /// <summary>
        /// 文件管理下载文件
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        FileDownloadReturnMessage DownloadFile(FileDownloadMessage request);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddFile(SysFileEntity file);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? UpdateFile(SysFileEntity file);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelFile(SysFileEntity file);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelFiles(List<SysFileEntity> files);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysFileEntity> GetSysFilesAllList(string rowId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetSysFilesDs(string rowId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetSysFilesAllDsByCondition(FileQueryCondition condition);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysFilePowerEntity> GetSysFileDutyPowerByFileId(string fileId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysFilePowerEntity> GetSysFileUserPowerByFileId(string fileId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddSysFilePower(SysFilePowerEntity filePower);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? AddSysFilePowers(List<SysFilePowerEntity> filePowers);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelSysFilePowers(List<SysFilePowerEntity> filePowers);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelSysFilePower(SysFilePowerEntity filePower);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        int? DelSysFileAndPower(SysFileEntity file);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetSysFilesAllDsByPowerCondition(string userNo, string[] dutyNos, FileQueryCondition queryCondition);

        /// <summary>
        /// 查询文件可接收的人
        /// </summary>
        /// <returns>USER_NO</returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetFileAcceptUser(string rowId);

        /// <summary>
        /// 根据用户，查询可接收的文件
        /// </summary>
        /// <param name="userNo"></param>
        /// <returns></returns>
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetAcceptFileByUserNo(string userNo, string rowId);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string CreateCalendar(List<SysPeriodEntity> period, List<SysWorkingPeriodEntity> workingPeriod);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string UpdateCalendar(SysPeriodEntity period, List<SysWorkingPeriodEntity> workingPeriod);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string DeleteCalendar(SysPeriodEntity period);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysPeriodEntity> GetCalendar(int year, int month);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysFcEntity> GetFcAllList();

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DataSet GetWorkingPeriod(int year, int month);

        #region 文件管理
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        FileUploadReturnMessage UploadFileInFileSystem(FileUploadInFileSystemMessage fileEntity);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        FileUploadReturnMessage UpdateSysFileInFileSystem(FileUploadInFileSystemMessage fileEntity);
        
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        DTOSysFileEntitys GetSysFileByLogicNo(string LogicNo);

        #endregion 文件管理

        #region SysStFile
        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        SysStFileEntity GetStFileByKey(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysStFileEntity> GetStFileAllByFormName(string formName);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string AddStFile(SysStFileEntity source);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        string UpdateStFile(SysStFileEntity source);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool DelStFile(SysStFileEntity source);

        #endregion

        #region 上传导入模板

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        SysImportTemplateEntity GetImportTemplateByKey(string id);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        SysImportTemplateEntity GetImportTemplate(string formName,string type);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        List<SysImportTemplateEntity> GetImportTemplateAllByFormName(string formName);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        ImportTemplateException ImportTemplateData(DataSet source, string formName);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool AddImportTemplate(SysImportTemplateEntity template);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool UpdateImportTemplate(SysImportTemplateEntity template);

        [OperationContract]
        [FaultContract(typeof(ProcessExecutionFault))]
        bool DelImportTemplate(SysImportTemplateEntity template);

        #endregion

    }


    [MessageContract]
    public class FileUploadMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public string ID;

        [MessageHeader(MustUnderstand = true)]
        public string FormName;

        [MessageHeader(MustUnderstand = true)]
        public string RowID;

        [MessageHeader(MustUnderstand = true)]
        public string Remark;

        [MessageHeader(MustUnderstand = true)]
        public string Name;

        [MessageHeader(MustUnderstand = true)]
        public string Type;

        [MessageHeader(MustUnderstand = true)]
        public string DeptNo;

        [MessageHeader(MustUnderstand = true)]
        public string UploadBy;

        [MessageBodyMember(Order = 1)]
        public Stream FileData;

    }

    [MessageContract]
    public class FileUploadReturnMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public string FilePath;
      
    }

    [MessageContract]
    public class FileDownloadMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public string FilePath;
    }

    [MessageContract]
    public class FileDownloadReturnMessage
    {
        [MessageBodyMember(Order = 1)]
        public byte[] FileData;
    }

    [MessageContract]
    public class AttachUploadMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public string ID;

        [MessageHeader(MustUnderstand = true)]
        public string FormName;

        [MessageHeader(MustUnderstand = true)]
        public string RowID;

        [MessageHeader(MustUnderstand = true)]
        public string Remark;

        [MessageHeader(MustUnderstand = true)]
        public string FileName;

        [MessageHeader(MustUnderstand = true)]
        public string UploadBy;

        [MessageBodyMember(Order = 1)]
        public Stream FileData;

    }

    [MessageContract]
    public class AttachUploadReturnMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public string FilePath;
    }

    [MessageContract]
    public class AttachDownloadReturnMessage
    {
        [MessageBodyMember(Order = 1)]
        public byte[] FileData;
    }


    [MessageContract]
    public class FileUploadInFileSystemMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public string ID;

        [MessageHeader(MustUnderstand = true)]
        public string FormName;

        [MessageHeader(MustUnderstand = true)]
        public string RowID;

        [MessageHeader(MustUnderstand = true)]
        public string Remark;

        [MessageHeader(MustUnderstand = true)]
        public string Name;

        [MessageHeader(MustUnderstand = true)]
        public string Type;

        [MessageHeader(MustUnderstand = true)]
        public string DeptNo;

        [MessageHeader(MustUnderstand = true)]
        public string UploadBy;

        [MessageHeader(MustUnderstand = true)]
        public string DocumentNo;

        [MessageHeader(MustUnderstand = true)]
        public string FileNo;

        [MessageHeader(MustUnderstand = true)]
        public DateTime ActiveDate;

        [MessageHeader(MustUnderstand = true)]
        public DateTime InactiveDate;

        [MessageHeader(MustUnderstand = true)]
        public string Ver;
        [MessageHeader(MustUnderstand = true)]
        public string ControlType;

        [MessageHeader(MustUnderstand = true)]
        public string FileExistsType;
        [MessageHeader(MustUnderstand = true)]
        public string SaveTimerange;

        [MessageHeader(MustUnderstand = true)]
        public string FilePosition;

        [MessageHeader(MustUnderstand = true)]
        public string FileStatus;
        [MessageHeader(MustUnderstand = true)]
        public string LogicNo;

        [MessageBodyMember(Order = 1)]
        public Stream FileData;

    }

}
